﻿using B.S.BasicData.Domain.SystemUsers;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfaces;
using B.S.BasicData.Write.Api.Application.Command.SystemUsers.IAMCommand;
using MediatR;

namespace B.S.BasicData.Write.Api.Application.CommandHandler.SystemUsers.IAMCommand
{
    /// <summary>
    /// 删除身份校验管理
    /// </summary>
    public class IAMDelCommandHandler:IRequestHandler<IAMDelCommand,ApiResult<int>>
    {
        private readonly IBaseRepository<IAM_Model> _baseRepository;

        public IAMDelCommandHandler(IBaseRepository<IAM_Model> baseRepository)
        {
            _baseRepository = baseRepository;
        }


        /// <summary>
        /// 删除身份校验管理
        /// </summary>
        public Task<ApiResult<int>> Handle(IAMDelCommand request, CancellationToken cancellationToken)
        {
            var res=new ApiResult<int>();
            var arrid=request.Id.Split(',');
            var result = _baseRepository.BatchDeleteByExpress(m=> arrid.Contains(m.Id.ToString()));
            if (result > 0) 
            {
                res.Msg = "删除成功";
                res.Data = result;
                res.Code=ApiEnums.Success;
            }
            return Task.FromResult(res);
        }
    }
}
